package org.yaac.client.ui;

import javax.inject.Inject;

import org.yaac.client.activity.MenuActivity;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class MenuViewImpl extends Composite implements MenuView {

	private static MenuViewImplUiBinder uiBinder = GWT
			.create(MenuViewImplUiBinder.class);

	@UiTemplate("MenuView.ui.xml")
	interface MenuViewImplUiBinder extends UiBinder<Widget, MenuViewImpl> {
	}

	@UiField(provided=true)
	CellTree mainMenu;
	
	/**
	 * 
	 */
	private MenuTreeViewModel viewModel;

	/**
	 * presenter
	 */
	@SuppressWarnings("unused")
	private MenuActivity listener;
	
	/**
	 * 
	 */
	@Inject
	MenuViewImpl(MenuTreeViewModel viewModel) {
		this.viewModel = viewModel; 
		
		mainMenu = new CellTree(this.viewModel, null);
		mainMenu.setAnimationEnabled(true);
		mainMenu.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
		mainMenu.ensureDebugId("mainMenu");
		
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void setPresenter(MenuActivity listener) {
		this.listener = listener;
	}
	
	@Override
	public void updateCurrPlace(String urlTokenPrefix) {
		viewModel.updateSelection(urlTokenPrefix);
	}
}
